﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class MatchInstructionsStep1 : System.Web.UI.Page
    {
        string MatchId = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.MatchInstructionsStep1_PageTitle;
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");
            
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            
            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");


            MatchId = ReurnMatchId();
            if (MatchId == null)
                Response.Redirect("GeneralMessage.aspx?MessageString=l43ZZOTLOB");

            if (!GND.ReadNivdalBoolData("@UserId", "@MatchId", "Nivdal_ShouldUserGiveInstructionsToMatch", ou.UserId, MatchId))
            {
                Response.Redirect("GeneralMessage.aspx?MessageString=ko3ATUOTLOB");
            }

            bool Explicit = false;
            if (Request.QueryString["explicit"] != null)
                Explicit = true;

            if ((GND.ReadNivdalIntData("@UserId", "Nivdal_GetMatchInstructionsType", ou.UserId) == "1" && !Explicit))
                Response.Redirect("MatchInstructions.aspx?MatchId=" + MatchId + "&explicit=true");

            //AdvancedIstructionsHyperlink.NavigateUrl = "MatchInstructions.aspx?MatchId=" + MatchId + "&explicit=true";
            this.PageNameLabel.Text = GND.ReadNivdalStringData("@MatchId", "Nivdal_GetMatchTitleString", MatchId) + " " + Resources.Resource.MatchInstructionsStep1_RightPageNameLabel;
            //this.Title = this.PageNameLabel.Text + " - nivdal.com!";
        }

        protected string ReurnMatchId()
        {
            string MatchId = null;
            if (Request.QueryString["MatchId"] != null)
                MatchId = Request.QueryString["MatchId"].ToString();
            return MatchId;
        }



        protected void NextButton_Click(object sender, EventArgs e)
        {
            string formation = "000";
            if (this.Button550.Checked)
                formation = "550";
            if (this.Button541.Checked)
                formation = "541";
            if (this.Button532.Checked)
                formation = "532";
            if (this.Button523.Checked)
                formation = "523";
            if (this.Button451.Checked)
                formation = "451";
            if (this.Button442.Checked)
                formation = "442";
            if (this.Button433.Checked)
                formation = "433";
            if (this.Button424.Checked)
                formation = "424";
            if (this.Button352.Checked)
                formation = "352";
            if (this.Button343.Checked)
                formation = "343";
            if (this.Button253.Checked)
                formation = "253";
            if (this.Button244.Checked)
                formation = "244";
            //if (this.AdvancedRadioButton.Checked)
            //    Response.Redirect("MatchInstructions.aspx?MatchId=" + MatchId + "&explicit=true");

            Response.Redirect("~/MatchInstructionsStep2.aspx?Formation=" + formation + "&MatchId=" + MatchId);
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}